package com.andyyan.elasticsearch.client.test.model;


import net.sf.json.JSONObject;

import java.io.Serializable;

/**
 * Created by yantingxin on 16-3-30.
 */
public class Brand implements Serializable {

    private static final long serialVersionUID = -1685840261891901793L;

    private long id;

    private String name;

    private String logo;

    private int industry;

    private int certificate;

    private boolean complete;

    public Brand() {
    }

    public Brand(String name, String logo, int industry, int certificate, boolean complete) {
        this.name = name;
        this.logo = logo;
        this.industry = industry;
        this.certificate = certificate;
        this.complete = complete;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLogo() {
        return logo;
    }

    public void setLogo(String logo) {
        this.logo = logo;
    }

    public int getIndustry() {
        return industry;
    }

    public void setIndustry(int industry) {
        this.industry = industry;
    }

    public int getCertificate() {
        return certificate;
    }

    public void setCertificate(int certificate) {
        this.certificate = certificate;
    }

    public boolean isComplete() {
        return complete;
    }

    public void setComplete(boolean complete) {
        this.complete = complete;
    }

    @Override
    public String toString() {
        return "Brand{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", logo='" + logo + '\'' +
                ", industry=" + industry +
                ", certificate=" + certificate +
                ", complete=" + complete +
                '}';
    }

    public static String getEsMapping(String type){
        JSONObject modelJson = new JSONObject();

        JSONObject jsonObject = new JSONObject();

        JSONObject propertyJson = new JSONObject();

        //id 的map
        JSONObject idJson = new JSONObject();
        idJson.put("type", "long");

        propertyJson.put("id", idJson);

        //name的map
        JSONObject nameJson = new JSONObject();
        nameJson.put("type", "string");
        nameJson.put("analyzer", "standard");

        propertyJson.put("name", nameJson);

        //logo
        JSONObject logoJson = new JSONObject();
        logoJson.put("type", "string");
        logoJson.put("index", "not_analyzed");

        propertyJson.put("logo", logoJson);


        //industry
        JSONObject industryJson = new JSONObject();
        industryJson.put("type", "integer");

        propertyJson.put("industry", industryJson);

        //certificate
        JSONObject certiJson = new JSONObject();
        certiJson.put("type", "integer");

        propertyJson.put("certificate", certiJson);

        //complete
        JSONObject completeJson = new JSONObject();
        completeJson.put("type", "boolean");

        propertyJson.put("complete", completeJson);

        jsonObject.put("properties", propertyJson);


        modelJson.put(type, jsonObject);

        return modelJson.toString();
    }
}
